package kz.kstu.scantest.app.delegate.impl;

import kz.kstu.scantest.app.delegate.api.AuditDelegate;
import kz.kstu.scantest.app.util.locator.ServiceLocator;
import kz.kstu.scantest.app.util.locator.factory.ServiceLocatorFactory;
import kz.kstu.scantest.business.common.exception.KeyAlreadyExists;
import kz.kstu.scantest.business.entity.Key;
import kz.kstu.scantest.facade.ejb.api.AuditFacade;

/**
 * @author Filipp_Stankevich
 *         created 02.09.12 21:55
 */
public class AuditDelegateImpl implements AuditDelegate {

    private AuditFacade getFormDataFacade(boolean isOnline) {
        ServiceLocator serviceLocator = ServiceLocatorFactory.getServiceLocator(isOnline);
        return serviceLocator.getService(AuditFacade.SERVICE_NAME, AuditFacade.class);
    }

    @Override
    public Integer getProcessedFormDataCount() {
        return getFormDataFacade(false).getProcessedFormDataCount();
    }

    @Override
    public void changeStatistic(Integer count) {
        getFormDataFacade(false).changeStatistic(count);
    }

    @Override
    public void saveKey(Key key) throws KeyAlreadyExists {
        getFormDataFacade(false).saveKey(key);
    }

    @Override
    public Key findLastKey() {
        return getFormDataFacade(false).findLastKey();
    }
}
